﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SubstringExtension
{
    static class Extension
    {
        public static String Substring(this StringBuilder sb, int index, int length)
        {
            StringBuilder result = new StringBuilder();
            for (int i = index; i < index + length; i++)
            {
                if (i < 0 || i > sb.Length) throw new IndexOutOfRangeException();
                result.Append(sb[i]);
            }
            return result.ToString();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder("This");
            Console.WriteLine(sb.Substring(2, 4));
        }
    }
}
